import {ActionType, PageContainer, ProColumns, ProTable} from "@ant-design/pro-components";
import React, {useRef} from "react";
import {globalLoadTableApi} from "@/services/admin-api/globalApi";

type CustomerAddress = {
  addressId: number;
  customerId: number;
  customerName: string;
  customerPhone: string;
  addressName: string;
  addressDetail: string;
  addressLat: number;
  addressLng: number;
  floor: number;
  elevator: boolean;
  delFlag: boolean;
  createTime: string;
  createUserId: number;
  createUserName: string;
  updateTime: string;
  updateUserId: number;
  updateUserName: string;
};

export default () => {

  const actionRef = useRef<ActionType>();

  const columns: ProColumns<CustomerAddress>[] = [
    {title: 'ID', dataIndex: 'addressId', valueType: 'digit', hideInSearch: true},
    {title: '客户ID', dataIndex: 'customerId', valueType: 'digit'},
    {title: '昵称', dataIndex: 'customerName', valueType: 'text', hideInSearch: true},
    {title: '电话', dataIndex: 'customerPhone', valueType: 'text', hideInSearch: true},
    {title: '地址', dataIndex: 'addressName', valueType: 'text', hideInSearch: true},
    {title: '地址补充', dataIndex: 'addressDetail', valueType: 'text', hideInSearch: true},
    {title: '楼层', dataIndex: 'floor', valueType: 'digit', hideInSearch: true},
    {
      title: '电梯',
      dataIndex: 'elevator',
      valueType: 'text',
      render: (_, record) => record.elevator.toString(),
      hideInSearch: true
    },
    {title: '创建时间', dataIndex: 'createTime', valueType: 'dateTime', hideInSearch: true,},
    {title: '创建用户ID', dataIndex: 'createUserId', valueType: 'digit', hideInSearch: true,},
    {title: '创建用户', dataIndex: 'createUserName', valueType: 'text', hideInSearch: true,},
    {title: '更新时间', dataIndex: 'updateTime', valueType: 'dateTime', hideInSearch: true,},
    {title: '更新用户ID', dataIndex: 'updateUserId', valueType: 'digit', hideInSearch: true,},
    {title: '更新用户', dataIndex: 'updateUserName', valueType: 'text', hideInSearch: true,},
  ];

  return <PageContainer header={{title: '', breadcrumb: {},}}>
    <ProTable<CustomerAddress>
      columns={columns} actionRef={actionRef}
      search={{span: 4}}
      request={async (param) => globalLoadTableApi('/customer/address/table', param)}
      rowKey={(record) => record.addressId}
      columnsState={{
        defaultValue: {
          delFlag: {show: false},
          createUserId: {show: false},
          updateUserId: {show: false}
        }
      }}/>

  </PageContainer>
}
